package maintain

import (
	"github.com/gin-gonic/gin"
	"golang.org/x/text/encoding/simplifiedchinese"
	"iot-base/common/webapi"
	"os/exec"
	"runtime"
)

func initNetstatAPI(r *gin.RouterGroup) {
	r.GET("/netstat", func(c *gin.Context) {

		if runtime.GOOS == "windows" {
			cmd := exec.Command("cmd", "/C", `netstat -ano`)
			out, _ := cmd.CombinedOutput()
			bout, _ := simplifiedchinese.GBK.NewDecoder().Bytes(out)
			webapi.SendResult(string(bout), nil, c)
		} else {
			cmd := exec.Command("netstat -anp")
			out, _ := cmd.CombinedOutput()
			webapi.SendResult(string(out), nil, c)
		}

	})
}
